home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Animation Wizard.dir / 00013_Script_ScoreMgr < prev    next >
Text File  |  1997-05-10  |  16KB  |  478 lines

  1. -- ScoreMgr script
  2.  
  3. property iUsersScoreSelection
  4. property iGeneratedScoreSelection
  5. property ichStart
  6. property ichEnd
  7. property iFrameStart
  8. property iFrameEnd
  9. property iStageWidth
  10. property iStageHeight
  11. property iStageRight
  12. property iStageBottom
  13. property iChannelAvailList
  14. property ichReselect
  15. property iLocReselect
  16.  
  17. property ikChStart
  18. property ikChEnd
  19. property ikFrameStart
  20. property ikFrameEnd
  21.  
  22. property iLastFrame
  23. property iNeedClean
  24.  
  25. on birth me
  26.   tell the stage
  27.     set iStageRight = the StageRight
  28.     set iStageBottom = the StageBottom
  29.     set iStageWidth = iStageRight - the StageLeft
  30.     set iStageHeight = iStageBottom - the StageTop
  31.   end tell
  32.   set ikChStart = 1
  33.   set ikChEnd = 2
  34.   set ikFrameStart = 3
  35.   set ikFrameEnd = 4
  36.   set iChannelAvailList = []
  37.   set iGeneratedScoreSelection = []
  38.   set ichReselect = 18
  39.   
  40.   return me
  41. end birth
  42.  
  43. on mGetStageWidth me
  44.   return iStageWidth
  45. end mGetStageWidth
  46.  
  47. on mGetStageHeight me
  48.   return iStageHeight
  49. end mGetStageHeight
  50.  
  51. on mGetStageRight me
  52.   return iStageRight
  53. end mGetStageRight
  54.  
  55. on mGetStageBottom me
  56.   return iStageBottom
  57. end mGetStageBottom
  58.  
  59. on mInit me, nFramesNeeded, nChannelsNeeded
  60.   global gDevelopmentFlag 
  61.   
  62.   if nFramesNeeded > 32000 then
  63.     alert("The combination of text and settings you have chosen would generate an " & ¼
  64.     "animation of more than 32000 frames.  Please simplify your selections and try again.")
  65.     return FALSE
  66.   end if
  67.   
  68.   tell the stage   
  69.     set iUsersScoreSelection = the scoreSelection
  70.     set iLastFrame = the lastFrame
  71.     set iStageRight = the StageRight   --check the stage location again, in case it has changed.
  72.     set iStageBottom = the StageBottom
  73.     set iStageWidth = iStageRight - the StageLeft
  74.     set iStageHeight = iStageBottom - the StageTop
  75.   end tell
  76.   if iUsersScoreSelection = [] then
  77.     alert("Please select a range of cells or frames in the score and try again.")
  78.     return FALSE
  79.   end if
  80.   
  81.   if gDevelopmentFlag then -- for development only
  82.     mForceSelection(me)    
  83.   end if
  84.   set iLocReselect = the loc of sprite ichReselect -- save for later
  85.   puppetSprite ichReselect, TRUE
  86.   
  87.   -- We must parse the user's selection and do the appropriate thing.
  88.   
  89.   set firstScoreSelectionList = getAt(iUsersScoreSelection, 1)
  90.   set ichStart = getAt(firstScoreSelectionList, ikChStart)
  91.   set ichEnd = getAt(firstScoreSelectionList, ikChEnd)
  92.   set iFrameStart = getAt(firstScoreSelectionList, ikFrameStart)
  93.   set iFrameEnd = getAt(firstScoreSelectionList, ikFrameEnd)
  94.   set theGeneratedFrameEnd = iFrameStart + nFramesNeeded - 1
  95.   
  96.   --check to see if the ending frame is the last frame and put in a tempo setting if it is.
  97.   set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  98.   if theEnd >= iLastFrame then
  99.     set iNeedClean = true
  100.     tell the stage
  101.       beginRecording
  102.         go to frame (theEnd + 5)
  103.         set the frameTempo to 5
  104.       endrecording
  105.     end tell
  106.   else 
  107.     set iNeedClean = false
  108.   end if
  109.   
  110.   set iChannelAvailList = []
  111.   if (ichStart = -5) and (ichEnd = 48) then -- user selected a whole frame
  112.     -- Make a list saying all 48 channels are available
  113.     repeat with ch = 1 to 48
  114.       add iChannelAvailList, ch
  115.     end repeat
  116.     
  117.     tell the stage
  118.       beginRecording
  119.         
  120.         -- If the user selected a range of full frames, delete these frames.
  121.         -- This will simulate an insertion cursor
  122.         if iFrameEnd >= iFrameStart then 
  123.           go to frame iFrameStart
  124.           repeat with theFrameNum = iFrameStart to iFrameEnd
  125.             -- The following line deletes any frame marker
  126.             set the frameLabel = 0
  127.             deleteFrame
  128.           end repeat 
  129.         end if
  130.         
  131.         -- Now we basically have an insertion cursor in the score
  132.         -- So, here we insert frames
  133.         tell the stage
  134.           if iFrameStart = 1 then
  135.             go to frame 1
  136.           else
  137.             go to frame iFrameStart - 1
  138.           end if
  139.           
  140.           repeat with i = 1 to nFramesNeeded
  141.             insertFrame
  142.           end repeat
  143.           
  144.           if iFrameStart = 1 then
  145.             go to frame 1
  146.           else
  147.             go to frame iFrameStart - 1
  148.           end if
  149.         end tell
  150.         
  151.         --check again, in case the ending frame got deleted while deleting & inserting frames.
  152.         set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  153.         if theEnd >= iLastFrame then
  154.           set iNeedClean = true
  155.           go to frame (theEnd + 5)
  156.           set the frameTempo to 5
  157.         else 
  158.           set iNeedClean = false
  159.         end if
  160.         
  161.       endRecording
  162.     end tell
  163.     set iGeneratedScoreSelection = [[-5, 48, iFrameStart, theGeneratedFrameEnd]]
  164.     
  165.     -- Otherwise, the user has selected  one or more channels  
  166.   else    
  167.     --  Build a list of channels that the user has selected.    
  168.     set iGeneratedScoreSelection  = []
  169.     set nItems = count(iUsersScoreSelection)
  170.     repeat with thisSelection = 1 to nItems
  171.       set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelection)
  172.       set thisChStart = getAt(thisScoreSelectionList, ikChStart)
  173.       if thisChStart <= 0 then
  174.         alert("Please make your score selection in channels 1 through 48")
  175.         mClean me
  176.         return FALSE
  177.       end if
  178.       set thisChEnd = getAt(thisScoreSelectionList, ikChEnd)
  179.       -- add this to the Generated score selection
  180.       set thisScoreSelection = [thisChStart, thisChEnd, iFrameStart, theGeneratedFrameEnd]
  181.       addAt(iGeneratedScoreSelection, thisScoreSelection)
  182.       
  183.       -- add each of the user's selected channels to the channel available list
  184.       repeat with thisCh = thisChStart to thisChEnd
  185.         add(iChannelAvailList, thisCh)
  186.       end repeat
  187.       
  188.     end repeat
  189.     set nChannelsAvail = count(iChannelAvailList)
  190.     if nChannelsNeeded > nChannelsAvail then
  191.       alert("Your animation requires" && nChannelsNeeded && "channels, " & ¼
  192.                 "but you have only selected" && nChannelsAvail && "channels.  " & ¼
  193.                  "Please select more and try again.")
  194.       mClean me
  195.       return FALSE
  196.     end if
  197.     
  198.     -- If we don't have enough frames in the selection,
  199.     -- duplicate the last frame until we have enough
  200.     --but make sure we don't duplicate the tempo channel
  201.     set nFramesSelected = iFrameEnd - iFrameStart + 1   
  202.     
  203.     if nFramesSelected < nFramesNeeded then
  204.       set nFramesToAdd = nFramesNeeded - nFramesSelected
  205.       tell the stage
  206.         go to frame iFrameEnd
  207.         beginRecording
  208.           
  209.           repeat with i = 1 to nFramesToAdd
  210.             duplicateFrame
  211.             set the frameTempo = 0
  212.           end repeat
  213.         endRecording
  214.         go to frame iFrameStart
  215.       end tell    
  216.     end if  --nFramesSelected
  217.   end if
  218.   
  219.   
  220.   -- Finally, clear out all user selected cells in the generated score
  221.   --  and clear out the tempo channel, in case of reselection
  222.   
  223.   tell the stage
  224.     beginRecording
  225.       go to frame iFrameStart
  226.       repeat with thisFrame = iFrameStart to iFrameEnd
  227.         repeat with chIndex = 1 to nChannelsAvail
  228.           set thisCh = getAt(iChannelAvailList, chIndex)
  229.           if the castNum of sprite thisCh <> 0 then
  230.             set the type of sprite thisCh = 0  --  delete anything that's there
  231.           end if
  232.         end repeat
  233.         set the frameTempo = 0
  234.         updateFrame
  235.       end repeat
  236.     endRecording
  237.   end tell
  238.   
  239.   
  240.   
  241.   --put "Channels that are available are :" && iChannelAvailList
  242.   --put "The Generated score selection is:" && iGeneratedScoreSelection
  243.   updateStage
  244.   
  245.   return TRUE  
  246. end mInit
  247.  
  248. on mShowReselect me
  249.   set the scoreSelection = iUsersScoreSelection
  250.   set the loc of sprite ichReselect = iLocReselect
  251.   set the castNum of sprite ichReselect = the number of cast "ReselectButton"
  252.   updateStage
  253. end mShowReselect
  254.  
  255.  
  256. on mForceSelection me  
  257.   -- This ensures that we don't overwrite stuff in the MIAW
  258.   -- when we are using it as a development movie (not a MIAW)
  259.   -- If I goofed and forgot to select a testing area of the score,
  260.   -- make believe I selected frames 101 to 125
  261.   
  262.   set nItems = count(iUsersScoreSelection)
  263.   repeat with thisSelectionNum = 1 to nItems
  264.     set thisScoreSelectionList = getAt(iUsersScoreSelection, thisSelectionNum)
  265.     set thisStart = getAt(thisScoreSelectionList, ikFrameStart)
  266.     set thisEnd = getAt(thisScoreSelectionList, ikFrameEnd)
  267.     
  268.     if (thisStart < 101) or (thisEnd < 101) then
  269.       setAt(thisScoreSelectionList, ikFrameStart, 101)
  270.       setAt(thisScoreSelectionList, ikFrameEnd, 125)
  271.       setAt(iUsersScoreSelection, thisSelectionNum, thisScoreSelectionList)
  272.     end if
  273.   end repeat
  274.   
  275. end mForceSelection
  276.  
  277. on mReselect me
  278.   if iGeneratedScoreSelection = [] then
  279.     alert("Internal error, mReselect - there is nothing to reselect.")
  280.     return
  281.   end if
  282.   tell the stage
  283.     set the scoreSelection = iGeneratedScoreSelection
  284.   end tell
  285. end mReselect
  286.  
  287. on mGetGeneratedScoreSelection me
  288.   return iGeneratedScoreSelection
  289. end mGetGeneratedScoreSelection
  290.  
  291.  
  292.  
  293. on mGetStartFrame me
  294.   return iFrameStart
  295. end mGetStartFrame
  296.  
  297. on mGetNextSelectedChannel me
  298.   -- Get the first in the list of users selected channels set up in mInit, 
  299.   -- return it, and eliminate it from the list of available channels
  300.   
  301.   if iChannelAvailList = [] then
  302.     alert("Internal error, mGetNextSelectedChannel is out of available channels")
  303.     return -99
  304.   end if
  305.   set theCh = getAt(iChannelAvailList, 1)
  306.   deleteAt(iChannelAvailList, 1)
  307.   
  308.   return theCh
  309. end mGetNextSelectedChannel
  310.  
  311.  
  312. on mWriteSprite me, f, ch, cm, theForeColor, theBackColor, x, y, w, h
  313.   global gkTransparentInk
  314.   
  315.   tell the stage
  316.     go frame ( f )
  317.     beginRecording 
  318.       -- sprite properties
  319.       set the castNum of sprite ch = cm
  320.       set the foreColor of sprite ch = theForeColor
  321.       set the backColor of sprite ch = theBackColor
  322.       set the locH  of sprite ch = x
  323.       set the locV  of sprite ch = y
  324.       set the ink of sprite ch = gkTransparentInk
  325.       set the tweened of sprite ch  to 1
  326.       
  327.       -- last two are primarily to support Zoom effect
  328.       if w <> 0 then 
  329.         set the width  of sprite ch = w
  330.       end if
  331.       if h <> 0 then 
  332.         set the height of sprite ch = h
  333.       end if
  334.       updateFrame
  335.       -- debug( "Writing Sprite:" && s && the type of sprite s && the castNum of sprite s && ¼
  336.              the foreColor of sprite s && the backColor of sprite s && ¼
  337.              the locH of sprite s && the locV of sprite s && ¼
  338.              the width of sprite s && the height of sprite s )
  339.     endRecording
  340.   end tell
  341. end mWriteScore
  342.  
  343. on mWriteFrameControl me, theFrame, theControl, theValue
  344.   if theControl = #Transition then -- copy a known transition
  345.     copyToClipBoard member (the number of member theValue)    
  346.     --  Create a cast member in the stage movie  
  347.     set castNumTransTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  348.   end if
  349.   tell the stage
  350.     go frame theFrame
  351.     beginRecording 
  352.       case theControl of
  353.         #Label:  set the frameLabel = theValue
  354.         #Tempo: set the frameTempo = theValue
  355.         #Transition:   -- Copied transition to clipboard already (above)
  356.           pasteClipboardInto member castNumTransTarget
  357.           set the name of member castNumTransTarget  = "Transition" && string(the ticks)
  358.           set the frameTransition = castNumTransTarget
  359.         #Sound1:  set the frameSound1 = theValue
  360.         #Sound2:  set the frameSound2 = theValue
  361.         otherwise  alert("Bad control value passed to mWriteFrameControl" & theControl)
  362.       end case   
  363.       updateFrame
  364.     endRecording
  365.   end tell  
  366. end mWriteFrameControl
  367.  
  368.  
  369. on mWriteFrameLabel me, theFrame, theLabel
  370.   mWriteFrameControl(me, theFrame, #Label, theLabel)
  371. end mWriteFrameLabel
  372.  
  373. -- Writing a frame delay is painful. Unfortunately, there is no
  374. -- easy way to just set this property.  So, we have to write 1
  375. -- frame for each second delay, and set the frame tempo
  376. -- of that frame to 1 frame per second.
  377. --on mWriteFrameDelay me, theFrame, nSeconds
  378. --  if nSeconds > 0 then
  379. --    repeat with thisFrame = 1 to nSeconds
  380. --      mWriteFrameControl(me, (theFrame + thisFrame - 1), #Tempo, 1)
  381. --    end repeat    
  382. --  end if  
  383. --end mWriteFrameDelay
  384.  
  385. --undocumented lingo: setting the frameTempo to a negative number sets it to wait for that many seconds.
  386. on mWriteFrameDelay me, theFrame, nSeconds
  387.   mWriteFrameControl(me,theFrame, #Tempo, -nSeconds )
  388. end mWriteFrameDelay
  389.  
  390. on mWriteFrameTempo me, theFrame, theTempo
  391.   mWriteFrameControl(me, theFrame, #Tempo, theTempo)
  392. end mWriteFrameTempo
  393.  
  394. on mWriteFrameTransition me, theFrame, theTransition
  395.   mWriteFrameControl(me, theFrame, #Transition, theTransition)
  396. end mWriteFrameTransition
  397.  
  398. on mWriteFrameSound1 me, theFrame, theSound1
  399.   mWriteFrameControl(me, theFrame, #Sound1, theSound1)
  400. end mWriteFrameSound1
  401.  
  402. on mWriteFrameSound2 me, theFrame, theSound2
  403.   mWriteFrameControl(me, theFrame, #Sound2, theSound2)
  404. end mWriteSound2
  405.  
  406.  
  407. -- pass in a list of all the frames to be recorded in and what to be recorded in each.
  408. on mWriteFrame me, frameList
  409.   global gkTransparentInk
  410.   tell the stage
  411.     beginRecording 
  412.       repeat with theFrameNum = 1 to count(frameList)
  413.         set theFrameStuff = getAt(frameList, theFrameNum)
  414.         --        put theFrameStuff
  415.         go to frame getAt(theFrameStuff, 1)
  416.         -- frame properties
  417.         repeat with theChannel = 2 to count(theFrameStuff)
  418.           set theChannelList = getAt(theFrameStuff, theChannel)
  419.           set theChannelType = getAt(theChannelList, 1)
  420.           case theChannelType of 
  421.             #label : set the frameLabel = getAt(theChannelList, 2)
  422.             #tempo : set the frameTempo = getAt(theChannelList, 2)
  423.             #palette : set the framePalette = getAt(theChannelList, 2)
  424.             #transition :  
  425.               set theTransition = getAt(theChannelList, 2)
  426.               set transitionMember = new(#transition)
  427.               if theTransition = "wipe down" then
  428.                 set the transitiontype of  transitionMember = 3
  429.                 set the chunkSize of transitionMember = 2
  430.               else if theTransition = "dissolve, pixels fast" then
  431.                 set the transitiontype of  transitionMember = 23
  432.                 set the chunkSize of transitionMember = 1
  433.               end if
  434.               set the duration of transitionMember = 2000
  435.               set the frameTransition = transitionMember
  436.             #sound1 :  set the frameSound1 = getAt(theChannelList, 2)
  437.             #sound2 :  set the frameSound2 = getAt(theChannelList, 2)
  438.             #sprite : 
  439.               set theSpriteNum = getAt(theChannelList, 2)
  440.               set the castNum of sprite theSpriteNum = getAt(theChannelList, 3)
  441.               set the foreColor of sprite theSpriteNum = getAt(theChannelList, 4)
  442.               set the backColor of sprite theSpriteNum = getAt(theChannelList, 5)
  443.               set the locH  of sprite theSpriteNum =getAt(theChannelList, 6)
  444.               set the locV  of sprite theSpriteNum = getAt(theChannelList, 7)
  445.               set the ink of sprite theSpriteNum = gkTransparentInk
  446.               set the tweened of sprite theSpriteNum  to 1
  447.               
  448.               set w = getAt(theChannelList, 8)
  449.               set h = getAt(theChannelList, 9)
  450.               -- last two are primarily to support Zoom effect
  451.               if w <> 0 then 
  452.                 set the width  of sprite theSpriteNum = w
  453.               end if
  454.               if h <> 0 then 
  455.                 set the height of sprite theSpriteNum = h
  456.               end if
  457.           end case
  458.           
  459.         end repeat  -- theChannel
  460.         updateFrame
  461.       end repeat  -- theFrameNum
  462.     endRecording
  463.   end tell
  464. end mWriteFrame
  465.  
  466. --gets rid of the extra tempo setting, if we set it. 
  467. on mClean me
  468.   if iNeedClean = true then
  469.     tell the stage
  470.       set iLastFrame = the lastFrame
  471.       beginRecording
  472.         go to frame iLastFrame
  473.         set the frameTempo to  0
  474.       endrecording
  475.     end tell
  476.   end if
  477. end mClean
  478.